/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.startup;


import ca.trader.logger.TraderLogger;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * The StartupListener, which listens to the Startup of the server.
 * When the server is starting, the contextInitialized method is called
 * @author Ahsan
 */
@WebListener
public class StartupListener implements ServletContextListener
{
	 private static final String _className = StartupListener.class.getName();
	 private ServletContext context;

	 /**
	  * When the server is starting, the this method is called
	  * @param contextEvent 
	  */
	 @Override
	 public void contextInitialized(ServletContextEvent contextEvent)
	 {
		  // initiate the logger
		  try
		  {
			   TraderLogger.init();
		  }
		  catch (IOException ex)
		  {
		  }
		  
		  TraderLogger.logInfo(_className, "contextInitialized", "Starting server");
		  // Get the servlet context
		  context = contextEvent.getServletContext();

		  // Call ServletContextManager directly
		  ServletContextManager manager = new ServletContextManager();
		  manager.startupInit(context);	
	 }
	 

	 
	 @Override
	 public void contextDestroyed(ServletContextEvent contextEvent)
	 {		  
		  TraderLogger.logInfo(_className, "contextDestroyed", "Shutting down server");
		  TraderLogger.exiting();		  
	 }

}